﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 生产单元
    /// </summary>
    public partial class WorkshoUnit : BusEntity
    {
        /// <summary>
        /// 生产区域ID
        /// </summary>
        public string AreaId { set; get; }
        /// <summary>
        /// 工序ID
        /// </summary>
        public string ProcessId { get; set; }
        /// <summary>
        /// 生产单元编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 生产单元名称
        /// </summary>
        public string Name { get; set; }
    }

    public partial class WorkshoUnit : BusEntity
    {
        /// <summary>
        /// 所属生产区域
        /// </summary>
        public WorkshoArea Area { set; get; }
        /// <summary>
        /// 生产单元下的工作
        /// </summary>
        public List<WorkshoStation> Stations { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class WorkshoUnitTypeConfig : BusEntityTypeConfig<WorkshoUnit>, IEntityTypeConfiguration<WorkshoUnit>
    {
        public override void Configure(EntityTypeBuilder<WorkshoUnit> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Area).WithMany(p => p.Units).HasForeignKey(p => p.AreaId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.AreaId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("生产单元");
            builder.Property(p => p.AreaId).HasComment("生产区域ID");
            builder.Property(p => p.Code).HasComment("生产单元编码");
            builder.Property(p => p.Name).HasComment("生产单元名称");
            #endregion

            #region 种子数据
            builder.HasData(new WorkshoUnit() { Id = "550182", ProcessId = "0010", Code = "550182", Name = "球冠压入中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550256", ProcessId = "0010", Code = "550256", Name = "耐磨条堆焊中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550221", ProcessId = "0010", Code = "550221", Name = "自动线拼版中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550193", ProcessId = "0010", Code = "550193", Name = "球冠焊接中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550185", ProcessId = "0020", Code = "550185", Name = "立式组队中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550257", ProcessId = "0020", Code = "550257", Name = "油压成型中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550186", ProcessId = "0030", Code = "550186", Name = "内环焊中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550222", ProcessId = "0030", Code = "550222", Name = "纵焊中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550187", ProcessId = "0040", Code = "550187", Name = "叶片摆搭中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550188", ProcessId = "0050", Code = "550188", Name = "叶片满焊中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550189", ProcessId = "0060", Code = "550189", Name = "合模中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new WorkshoUnit() { Id = "550191", ProcessId = "0080", Code = "550191", Name = "环焊中心", AreaId = "1001", CreateUserId = "1", ModifyUserId = "1" });            
            #endregion
        }
    }
}
